package com.ra.service.impl;

import com.ra.pojo.Job;
import com.ra.mapper.JobMapper;
import com.ra.pojo.RespPageBean;
import com.ra.pojo.dto.*;
import com.ra.service.IJobService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ra.utils.ScheduleUtil;
import lombok.SneakyThrows;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * <p>
 * 定时任务调度表 服务实现类
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements IJobService {

    @Autowired
    private Scheduler scheduler;

    @Autowired
    private JobMapper jobMapper;


    @SneakyThrows
    @PostConstruct
    public void init() {
        scheduler.clear();
        List<Job> jobs = jobMapper.selectList(null);
        for (Job job : jobs) {
            ScheduleUtil.createScheduleJob(scheduler, job);
        }
    }




}
